package homework;

public class Test03_ShoppingCart {
    public static void main(String[] args) {
        Product[] p1 = {new Product("abc",5,"abc"),
                new Product("abc",4,"abc"),
                new Product("abc",6,"abc"),
                new Product("abc",10,"abc"),
                new Product("abc",20,"abc")};
        ShoppingCart c = new ShoppingCart();
        c.addProduct(p1);
        System.out.println(c.getSum());
    }
}
class Product{
    private String name;
    private double price;
    private String description;
    public Product(String name,
                   double price,
                   String description) {
        this.name = name;
        this.price = price;
        this.description = description;
    }
    public double getPrice(){
        return price;
    }
}
class ShoppingCart{
    private Product[] p = new Product[5];
    //计算商品的总价
    public double getSum(){
        double sum = 0;
        for(int i=0;i< p.length;i++){
            sum+=p[i].getPrice();
        }
        return sum;
    }
    public void addProduct(Product[] p1){
        for(int i=0;i<p.length;i++){
            p[i] = p1[i];
        }
    }
}
